#ifndef MESSAGE_H
#define MESSAGE_H

#include <defs/export.h>
#include <defs/global.h>
#include <QByteArray>

#include <core/entityobject.h>
#include "header.h"
#include <log4qt/logger.h>
#include <QByteArray>

namespace Opl { namespace Protocol {

class PROTOCOL_EXPORT Message : public Opl::Core::EntityObject
{
		Q_OBJECT
//	Q_PROPERTY()
	public:		
		Message(Opl::Core::EntityObject* parent = 0);
		Message(const QByteArray& bytes);
		Message(const Message& msg);

		Message& operator = (const Message& that);

		bool isValid();

		const Header& header()const;
		void setHeader(const Header& hdr);

		const QByteArray& data()const;
		void setData(const QByteArray& d);

		virtual ~Message();
		static Message fromByteArray(const QByteArray& bytes);
	private:
		struct MESSAGE{
			Header hdr;
			QByteArray data;
		};		

		MESSAGE msg;
		bool isvalid;

};

PROTOCOL_EXPORT QDataStream& operator << (QDataStream& stream, const Message& msg);
PROTOCOL_EXPORT QDataStream& operator >> (QDataStream& stream, Message& msg);

}}

#endif // MESSAGE_H

